home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-20 | 11.0 KB | 282 lines | [TEXT/CWIE] |
- /*
- File: EveryItemProxy.c
-
- Contains: A proxy token for 'kAEAll' (every item of...)
-
- Previously, 'kAEAll' just made a set of tokens
- for every item in the specified container. This
- worked fine, but if an event did a get-data event
- on the resulting token without asking for a
- specific type, then the result would be a single
- reference if there was but one child, or a list
- if there were multiple items. This was somewhat
- counter-intuitive, as it was expected that the
- result of 'every item of...' would always be a list,
- even if there was only a single object.
-
- Making a proxy for 'kAEAll' allowed this discrepency
- to be fixed, as it provids a way to specify that the
- default type for 'kAEAll' is typeList rather than
- typeObjectSpecifier. It also avoids copious-property-token
- hell in cases such as "name of every item of..."
-
- Written by: Greg Anderson
-
- Copyright: © 1993-1995 by Apple Computer, Inc., all rights reserved.
-
- <8> 6/23/95 ga
- */
-
- #ifdef MWTRACEBACKTABLES
- #pragma traceback on
- #endif
-
- #include "EveryItemProxy.h"
- #include "ScriptableObjectList.h"
-
- #include <AERegistry.h>
- #include <AEObjects.h>
-
- #include "Exceptions.h"
-
- //========================================================================================
- // CLASS TEveryItemProxy
- //
- // This token represents every child of some other object
- //========================================================================================
-
-
- #pragma segment ObjectResident
- ImplementSmallClassData(TEveryItemProxy, clEveryItem);
-
- #pragma segment Foundation
-
- //----------------------------------------------------------------------------------------
- // TEveryItemProxy::TEveryItemProxy:
- //----------------------------------------------------------------------------------------
- TEveryItemProxy::TEveryItemProxy()
- {
- fDesiredClass = typeWildCard;
- } // TEveryItemProxy::TEveryItemProxy
-
- //----------------------------------------------------------------------------------------
- // TEveryItemProxy::~TEveryItemProxy:
- //----------------------------------------------------------------------------------------
- TEveryItemProxy::~TEveryItemProxy()
- {
- } // TEveryItemProxy::~TEveryItemProxy
-
- //----------------------------------------------------------------------------------------
- // TEveryItemProxy::IEveryItemProxy:
- //----------------------------------------------------------------------------------------
- void TEveryItemProxy::IEveryItemProxy(TAbstractScriptableObject* objectOfDesignation, DescType desiredClass)
- {
- fDesiredClass = desiredClass;
-
- Inherited::IProxyToken(objectOfDesignation);
- } // TEveryItemProxy::IEveryItemProxy
-
- //----------------------------------------------------------------------------------------
- // TEveryItemProxy::DerivedFromOSLClass:
- //----------------------------------------------------------------------------------------
- Boolean TEveryItemProxy::DerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
- {
- return (objectClass == kAEAll) || (Inherited::DerivedFromOSLClass(t, objectClass));
- } // TEveryItemProxy::DerivedFromOSLClass
-
- //----------------------------------------------------------------------------------------
- // TEveryItemProxy::DirectObjectIterator
- //----------------------------------------------------------------------------------------
- TAbstractObjectIterator* TEveryItemProxy::DirectObjectIterator(const TAETransaction& t)
- {
- TAbstractObjectIterator* delegateElements = this->ObjectOfDesignation()->ElementIterator(t);
-
- if(fDesiredClass == typeWildCard)
- return delegateElements;
- else
- return new TEveryElementOfClassIterator(fDesiredClass, delegateElements);
- }
-
- //========================================================================================
- // Class TEveryElementOfClassIterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::~TEveryElementOfClassIterator
- //----------------------------------------------------------------------------------------
- TEveryElementOfClassIterator::~TEveryElementOfClassIterator()
- {
- if(fIter)
- fIter->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::Reset
- //----------------------------------------------------------------------------------------
- void TEveryElementOfClassIterator::Reset(const TAETransaction& t, Boolean iterationDirection /* = kForwardIteration */)
- {
- //
- // Reset to the beginning
- //
- if(fIter)
- {
- fIter->Reset(t, iterationDirection);
-
- //
- // Then skip past items that are not derived from our restricted class
- //
- while(this->More(t) && (this->CurrentDerivedFromOSLClass(t, fDesiredClass) == false))
- fIter->Next(t);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::More
- //----------------------------------------------------------------------------------------
- Boolean TEveryElementOfClassIterator::More(const TAETransaction& t) const
- {
- if(fIter)
- return fIter->More(t);
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::Next
- //----------------------------------------------------------------------------------------
- void TEveryElementOfClassIterator::Next(const TAETransaction& t)
- {
- if(fIter)
- {
- //
- // Go to the next item in the list
- //
- fIter->Next(t);
-
- //
- // Also skip past items that are not derived from our restricted class
- //
- while(this->More(t) && (this->CurrentDerivedFromOSLClass(t, fDesiredClass) == false))
- fIter->Next(t);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::Current
- //----------------------------------------------------------------------------------------
- TAbstractScriptableObject* TEveryElementOfClassIterator::Current(const TAETransaction& t)
- {
- if(fIter)
- return fIter->Current(t);
- else
- return nil;
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::CurrentDerivedFromOSLClass
- //----------------------------------------------------------------------------------------
- Boolean TEveryElementOfClassIterator::CurrentDerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
- {
- if(fIter)
- return fIter->CurrentDerivedFromOSLClass(t, objectClass);
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::CountElements
- //----------------------------------------------------------------------------------------
- long TEveryElementOfClassIterator::CountElements(const TAETransaction& t, DescType desiredClass)
- {
- DescType desiredClassToUse = this->DetermineAccessClass(desiredClass);
- long count = 0;
-
- //
- // If we can divine the correct desired class, then call our
- // iterator to count the elements (may be an optimized version
- // of 'CountElements'). If we cannot divine the correct desired
- // class ("every alias file of every file of..."), then call
- // Inherited::CountElements, which will always work but may be slower
- // than calling the iterator directly.
- //
- if((fIter) && (desiredClassToUse != 0))
- return fIter->CountElements(t, desiredClassToUse);
- else
- return TAbstractObjectIterator::CountElements(t, desiredClass);
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::GetIndexedElement
- //----------------------------------------------------------------------------------------
- TAbstractScriptableObject* TEveryElementOfClassIterator::GetIndexedElement(const TAETransaction& t, DescType desiredClass, long index)
- {
- DescType desiredClassToUse = this->DetermineAccessClass(desiredClass);
-
- if((fIter) && (desiredClassToUse != 0))
- return fIter->GetIndexedElement(t, desiredClassToUse, index);
- else
- return TAbstractObjectIterator::GetIndexedElement(t, desiredClass, index);
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::GetNamedElement
- //----------------------------------------------------------------------------------------
- TAbstractScriptableObject* TEveryElementOfClassIterator::GetNamedElement(const TAETransaction& t, DescType desiredClass, TDescriptor nameDesc)
- {
- DescType desiredClassToUse = this->DetermineAccessClass(desiredClass);
-
- if((fIter) && (desiredClassToUse != 0))
- return fIter->GetNamedElement(t, desiredClassToUse, nameDesc);
- else
- return TAbstractObjectIterator::GetNamedElement(t, desiredClass, nameDesc);
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::SearchDeep
- //----------------------------------------------------------------------------------------
- void TEveryElementOfClassIterator::SearchDeep(const TAETransaction& t, TAbstractCollector* collector, DescType desiredClass, TAbstractSearchSpec* searchSpec)
- {
- this->RecursiveSearchDeep(t, collector, desiredClass, searchSpec);
- } // TEveryElementOfClassIterator::SearchDeep
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::Contains
- //----------------------------------------------------------------------------------------
- Boolean TEveryElementOfClassIterator::Contains(const TAETransaction& t, TAbstractScriptableObject* objectToTestForMembership)
- {
- if(fIter)
- return fIter->Contains(t, objectToTestForMembership);
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // TEveryElementOfClassIterator::DetermineAccessClass:
- //
- // This is used when someone says 'alias file 3 of every item of...'
- // In this example, 'alias file' is the desired class, and 'item' is
- // fDesiredClass. This example should be the same as the statement
- // 'item 3 of every alias file of...', and 'alias file 3 of every alias file of...'.
- //
- // We currently are not smart enough to handle 'alias file 3 of every file of...',
- // because to do that we would have to know whether alias file or file is more
- // specific. In that case we return '0' as the desired class to use, which
- // signals the iterator to fall back on slower iteration methods that handle the
- // more complex cases.
- //----------------------------------------------------------------------------------------
- DescType TEveryElementOfClassIterator::DetermineAccessClass(DescType desiredClass)
- {
- if((desiredClass == fDesiredClass) || (desiredClass == typeWildCard) || (desiredClass == cObject) || (desiredClass == cItem))
- return fDesiredClass;
- else if((fDesiredClass == typeWildCard) || (fDesiredClass == cObject) || (fDesiredClass == cItem))
- return desiredClass;
-
- //
- // We don't know which class is more specific (or if they intersect
- // at all), so return 0 to signal this fact.
- //
- return 0;
- } // TEveryElementOfClassIterator::DetermineAccessClass
-
- #pragma segment CFrontCruft
-